{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Selecting Subsets of Data in Pandas\n",
    "\n",
    "This notebook is also available as a [blog post on Medium](https://medium.com/dunder-data/selecting-subsets-of-data-in-pandas-part-3-d5704b4b9116).\n",
    "\n",
    "## Part 3: Assigning subsets of data\n",
    "This is part 3 of a 7-part series on how to select subsets of data from a pandas DataFrame or Series. Pandas offers a wide variety of options for subset selection which necessitates multiple articles. This series is broken down into the following 7 topics.\n",
    "\n",
    "1. Selection with `[]`, `.loc` and `.iloc`\n",
    "1. Boolean indexing\n",
    "1. Assigning subsets of data\n",
    "1. Selection with a MultiIndex\n",
    "1. Selecting subsets of data with methods\n",
    "1. Selections with other Index types\n",
    "1. Internals, Miscellaneous, and Conclusion\n",
    "\n",
    "## Assignment\n",
    "When you see the word **assign** used during a discussion on programming, it usually means that a variable is set equal to some value. For most programming languages, this means using the equal sign. For instance, to assign the value 5 to the variable **`x`** in Python, we do the following:\n",
    "\n",
    "```Python\n",
    "x = 5\n",
    "```\n",
    "\n",
    "This is formally called an [assignment statement][1]. More generally, we can define Python assignment statements as follows:\n",
    "\n",
    "```Python\n",
    "variable = expression\n",
    "```\n",
    "\n",
    "There is quite a bit more to the [Python assignment statement](https://docs.python.org/3/reference/simple_stmts.html), but for our purposes it just means using the equal sign to store the object on the right-hand side to the left-hand side.\n",
    "\n",
    "## Documentation on Assigning subsets of data\n",
    "There isn't one particular sub-section of the documentation that covers this topic precisely. Several examples are available throughout the entire [indexing section](http://pandas.pydata.org/pandas-docs/stable/indexing.html).\n",
    "\n",
    "## What does this have to do with selecting subsets of data?\n",
    "In this article, we will use the assignment statement, but only after we select a subset of data. We will be doing our subset selection based on what we learned from [part 1](https://medium.com/dunder-data/selecting-subsets-of-data-in-pandas-6fcd0170be9c) and [part 2](https://medium.com/dunder-data/selecting-subsets-of-data-in-pandas-39e811c81a0c) and changing just those values.\n",
    "\n",
    "The left-hand side will have our subset selection and the right-hand side will contain our new values like this:\n",
    "\n",
    "```Python\n",
    "subset_of_DataFrame_or_Series = new_values\n",
    "```\n",
    "\n",
    "## Small Sample Dataset\n",
    "During this tutorial, we will be working with a small sample of the [employee](Dataset%20Descriptions.ipynb#Employee-Data) dataset. The small dataset will help us immediately see the changes. Let's take a look at this dataset now, which uses the index to store the names of each employee.\n",
    "\n",
    "[1]: https://en.wikipedia.org/wiki/Assignment_(computer_science)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>GENDER</th>\n",
       "      <th>RACE</th>\n",
       "      <th>DEPARTMENT</th>\n",
       "      <th>YEARS EXPERIENCE</th>\n",
       "      <th>SALARY</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Tom</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>23</td>\n",
       "      <td>107962</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Niko</th>\n",
       "      <td>Male</td>\n",
       "      <td>Black</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>1</td>\n",
       "      <td>30347</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Penelope</th>\n",
       "      <td>Female</td>\n",
       "      <td>White</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>12</td>\n",
       "      <td>60258</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aria</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>8</td>\n",
       "      <td>43618</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sofia</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>23</td>\n",
       "      <td>26125</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dean</th>\n",
       "      <td>Male</td>\n",
       "      <td>Black</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>3</td>\n",
       "      <td>33592</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zach</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>4</td>\n",
       "      <td>37565</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          GENDER   RACE          DEPARTMENT  YEARS EXPERIENCE  SALARY\n",
       "Tom         Male  White         Engineering                23  107962\n",
       "Niko        Male  Black         Engineering                 1   30347\n",
       "Penelope  Female  White         Engineering                12   60258\n",
       "Aria      Female  Black         Engineering                 8   43618\n",
       "Sofia     Female  Black  Parks & Recreation                23   26125\n",
       "Dean        Male  Black  Parks & Recreation                 3   33592\n",
       "Zach        Male  White  Parks & Recreation                 4   37565"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv('../../data/employee_sample.csv', index_col=0)\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Creating a new column\n",
    "Before we change any of the data in this DataFrame, we will add a single column to the end. There are multiple ways of doing so, but we will begin by using *just the indexing operator* (the brackets). Place a string inside of the brackets and make this the left-hand side of the assignment.\n",
    "\n",
    "The right-hand side can consist of any of the following:\n",
    "* A scalar value\n",
    "* A list or array with the same length as the DataFrame\n",
    "* A pandas Series with an index that matches the index of the DataFrame (a little tricky!)\n",
    "\n",
    "## New column assigned to a scalar value\n",
    "A **scalar** value is simply one single value, like an integer, string, boolean or date. When using a scalar for column assignment, each value in the column will be the same. Let's create a column **`SCORE`** and assign it the value 99."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "df['SCORE'] = 99"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Where's the output?\n",
    "In the previous two notebooks, we were only making column selections (no equal signs) resulting in output displayed directly into the notebook after executing the line of code. In the above, we made an assignment, which will not yield any output. We must use an extra line to display our data."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>GENDER</th>\n",
       "      <th>RACE</th>\n",
       "      <th>DEPARTMENT</th>\n",
       "      <th>YEARS EXPERIENCE</th>\n",
       "      <th>SALARY</th>\n",
       "      <th>SCORE</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Tom</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>23</td>\n",
       "      <td>107962</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Niko</th>\n",
       "      <td>Male</td>\n",
       "      <td>Black</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>1</td>\n",
       "      <td>30347</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Penelope</th>\n",
       "      <td>Female</td>\n",
       "      <td>White</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>12</td>\n",
       "      <td>60258</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aria</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>8</td>\n",
       "      <td>43618</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sofia</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>23</td>\n",
       "      <td>26125</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dean</th>\n",
       "      <td>Male</td>\n",
       "      <td>Black</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>3</td>\n",
       "      <td>33592</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zach</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>4</td>\n",
       "      <td>37565</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          GENDER   RACE          DEPARTMENT  YEARS EXPERIENCE  SALARY  SCORE\n",
       "Tom         Male  White         Engineering                23  107962     99\n",
       "Niko        Male  Black         Engineering                 1   30347     99\n",
       "Penelope  Female  White         Engineering                12   60258     99\n",
       "Aria      Female  Black         Engineering                 8   43618     99\n",
       "Sofia     Female  Black  Parks & Recreation                23   26125     99\n",
       "Dean        Male  Black  Parks & Recreation                 3   33592     99\n",
       "Zach        Male  White  Parks & Recreation                 4   37565     99"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Create a new column with a list or array\n",
    "\n",
    "Instead of creating a new column with all the same values, we can use a list or NumPy array with different values for each row. The only stipulation is that the number of new values in the list/array must be the same as the number of rows in the DataFrame.\n",
    "\n",
    "Let's create the column **`BONUS RATE`**, with a list of numbers between 0 and 1."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>GENDER</th>\n",
       "      <th>RACE</th>\n",
       "      <th>DEPARTMENT</th>\n",
       "      <th>YEARS EXPERIENCE</th>\n",
       "      <th>SALARY</th>\n",
       "      <th>SCORE</th>\n",
       "      <th>BONUS RATE</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Tom</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>23</td>\n",
       "      <td>107962</td>\n",
       "      <td>99</td>\n",
       "      <td>0.20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Niko</th>\n",
       "      <td>Male</td>\n",
       "      <td>Black</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>1</td>\n",
       "      <td>30347</td>\n",
       "      <td>99</td>\n",
       "      <td>0.10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Penelope</th>\n",
       "      <td>Female</td>\n",
       "      <td>White</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>12</td>\n",
       "      <td>60258</td>\n",
       "      <td>99</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aria</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>8</td>\n",
       "      <td>43618</td>\n",
       "      <td>99</td>\n",
       "      <td>0.15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sofia</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>23</td>\n",
       "      <td>26125</td>\n",
       "      <td>99</td>\n",
       "      <td>0.12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dean</th>\n",
       "      <td>Male</td>\n",
       "      <td>Black</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>3</td>\n",
       "      <td>33592</td>\n",
       "      <td>99</td>\n",
       "      <td>0.30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zach</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>4</td>\n",
       "      <td>37565</td>\n",
       "      <td>99</td>\n",
       "      <td>0.05</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          GENDER   RACE          DEPARTMENT  YEARS EXPERIENCE  SALARY  SCORE  \\\n",
       "Tom         Male  White         Engineering                23  107962     99   \n",
       "Niko        Male  Black         Engineering                 1   30347     99   \n",
       "Penelope  Female  White         Engineering                12   60258     99   \n",
       "Aria      Female  Black         Engineering                 8   43618     99   \n",
       "Sofia     Female  Black  Parks & Recreation                23   26125     99   \n",
       "Dean        Male  Black  Parks & Recreation                 3   33592     99   \n",
       "Zach        Male  White  Parks & Recreation                 4   37565     99   \n",
       "\n",
       "          BONUS RATE  \n",
       "Tom             0.20  \n",
       "Niko            0.10  \n",
       "Penelope        0.00  \n",
       "Aria            0.15  \n",
       "Sofia           0.12  \n",
       "Dean            0.30  \n",
       "Zach            0.05  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['BONUS RATE'] = [.2, .1, 0, .15, .12, .3, .05]\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We could have just as easily used a one dimensional NumPy array to get the same exact results. Let's do just that and create a random array of integers to represent the floor that the employee works on.\n",
    "\n",
    "We use the **`randint`** function from NumPy's **`rand`** module. Use the **`low`** (inclusive) and **`high`** (exclusive) parameters to bound the range of possible integers. **`len(df)`** returns the number of rows in the DataFrame ensuring that the size of the array is correct.."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([9, 4, 6, 8, 6, 8, 7])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "floor = np.random.randint(low=1, high=10, size=len(df))\n",
    "floor"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Then assign this to the **`FLOOR`** column:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>GENDER</th>\n",
       "      <th>RACE</th>\n",
       "      <th>DEPARTMENT</th>\n",
       "      <th>YEARS EXPERIENCE</th>\n",
       "      <th>SALARY</th>\n",
       "      <th>SCORE</th>\n",
       "      <th>BONUS RATE</th>\n",
       "      <th>FLOOR</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Tom</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>23</td>\n",
       "      <td>107962</td>\n",
       "      <td>99</td>\n",
       "      <td>0.20</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Niko</th>\n",
       "      <td>Male</td>\n",
       "      <td>Black</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>1</td>\n",
       "      <td>30347</td>\n",
       "      <td>99</td>\n",
       "      <td>0.10</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Penelope</th>\n",
       "      <td>Female</td>\n",
       "      <td>White</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>12</td>\n",
       "      <td>60258</td>\n",
       "      <td>99</td>\n",
       "      <td>0.00</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aria</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>8</td>\n",
       "      <td>43618</td>\n",
       "      <td>99</td>\n",
       "      <td>0.15</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sofia</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>23</td>\n",
       "      <td>26125</td>\n",
       "      <td>99</td>\n",
       "      <td>0.12</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dean</th>\n",
       "      <td>Male</td>\n",
       "      <td>Black</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>3</td>\n",
       "      <td>33592</td>\n",
       "      <td>99</td>\n",
       "      <td>0.30</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zach</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>4</td>\n",
       "      <td>37565</td>\n",
       "      <td>99</td>\n",
       "      <td>0.05</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          GENDER   RACE          DEPARTMENT  YEARS EXPERIENCE  SALARY  SCORE  \\\n",
       "Tom         Male  White         Engineering                23  107962     99   \n",
       "Niko        Male  Black         Engineering                 1   30347     99   \n",
       "Penelope  Female  White         Engineering                12   60258     99   \n",
       "Aria      Female  Black         Engineering                 8   43618     99   \n",
       "Sofia     Female  Black  Parks & Recreation                23   26125     99   \n",
       "Dean        Male  Black  Parks & Recreation                 3   33592     99   \n",
       "Zach        Male  White  Parks & Recreation                 4   37565     99   \n",
       "\n",
       "          BONUS RATE  FLOOR  \n",
       "Tom             0.20      9  \n",
       "Niko            0.10      4  \n",
       "Penelope        0.00      6  \n",
       "Aria            0.15      8  \n",
       "Sofia           0.12      6  \n",
       "Dean            0.30      8  \n",
       "Zach            0.05      7  "
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['FLOOR'] = floor\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Creating a new column with a Series (tricky!)\n",
    "Let's create a new pandas Series and see what happens when we attempt to assign it as a new column in our DataFrame.\n",
    "\n",
    "Let's try and add a column for the last name of each person."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       Smith\n",
       "1       Jones\n",
       "2    Williams\n",
       "3       Green\n",
       "4       Brown\n",
       "5     Simpson\n",
       "6      Peters\n",
       "dtype: object"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "last_name = pd.Series(['Smith', 'Jones', 'Williams', 'Green', 'Brown', 'Simpson', 'Peters'])\n",
    "last_name"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Make the assignment like we have done above:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>GENDER</th>\n",
       "      <th>RACE</th>\n",
       "      <th>DEPARTMENT</th>\n",
       "      <th>YEARS EXPERIENCE</th>\n",
       "      <th>SALARY</th>\n",
       "      <th>SCORE</th>\n",
       "      <th>BONUS RATE</th>\n",
       "      <th>FLOOR</th>\n",
       "      <th>LAST NAME</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Tom</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>23</td>\n",
       "      <td>107962</td>\n",
       "      <td>99</td>\n",
       "      <td>0.20</td>\n",
       "      <td>9</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Niko</th>\n",
       "      <td>Male</td>\n",
       "      <td>Black</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>1</td>\n",
       "      <td>30347</td>\n",
       "      <td>99</td>\n",
       "      <td>0.10</td>\n",
       "      <td>4</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Penelope</th>\n",
       "      <td>Female</td>\n",
       "      <td>White</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>12</td>\n",
       "      <td>60258</td>\n",
       "      <td>99</td>\n",
       "      <td>0.00</td>\n",
       "      <td>6</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aria</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>8</td>\n",
       "      <td>43618</td>\n",
       "      <td>99</td>\n",
       "      <td>0.15</td>\n",
       "      <td>8</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sofia</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>23</td>\n",
       "      <td>26125</td>\n",
       "      <td>99</td>\n",
       "      <td>0.12</td>\n",
       "      <td>6</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dean</th>\n",
       "      <td>Male</td>\n",
       "      <td>Black</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>3</td>\n",
       "      <td>33592</td>\n",
       "      <td>99</td>\n",
       "      <td>0.30</td>\n",
       "      <td>8</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zach</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>4</td>\n",
       "      <td>37565</td>\n",
       "      <td>99</td>\n",
       "      <td>0.05</td>\n",
       "      <td>7</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          GENDER   RACE          DEPARTMENT  YEARS EXPERIENCE  SALARY  SCORE  \\\n",
       "Tom         Male  White         Engineering                23  107962     99   \n",
       "Niko        Male  Black         Engineering                 1   30347     99   \n",
       "Penelope  Female  White         Engineering                12   60258     99   \n",
       "Aria      Female  Black         Engineering                 8   43618     99   \n",
       "Sofia     Female  Black  Parks & Recreation                23   26125     99   \n",
       "Dean        Male  Black  Parks & Recreation                 3   33592     99   \n",
       "Zach        Male  White  Parks & Recreation                 4   37565     99   \n",
       "\n",
       "          BONUS RATE  FLOOR LAST NAME  \n",
       "Tom             0.20      9       NaN  \n",
       "Niko            0.10      4       NaN  \n",
       "Penelope        0.00      6       NaN  \n",
       "Aria            0.15      8       NaN  \n",
       "Sofia           0.12      6       NaN  \n",
       "Dean            0.30      8       NaN  \n",
       "Zach            0.05      7       NaN  "
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['LAST NAME'] = last_name\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## All missing values!\n",
    "Our attempt failed because pandas uses a completely different methodology for combining two pandas objects. \n",
    "\n",
    "## Automatic alignment of the Index\n",
    "Whenever two pandas objects are combined in some fashion the row/column index of one is aligned with the row/column index of the other. This all happens silently and implicitly behind the scenes. So if you are unaware of it, you will be completely taken by surprise. I will dedicate several notebooks in a different section to this surprising yet powerful feature.\n",
    "\n",
    "Our operation failed to add the last names because the index of our Series is the integers 0 through 6, while the index of the DataFrame are the names of the employees. There are no index values in common between the objects, so pandas defaults to NaN (Not a number).\n",
    "\n",
    "## Create a Series with same Index as DataFrame\n",
    "To use a Series to create a new column, the index must match that of the modifying DataFrame. Let's re-create our Series with the same index as the DataFrame."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Tom            Smith\n",
       "Niko           Jones\n",
       "Penelope    Williams\n",
       "Aria           Green\n",
       "Sofia          Brown\n",
       "Dean         Simpson\n",
       "Zach          Peters\n",
       "dtype: object"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "last_name = pd.Series(data=['Smith', 'Jones', 'Williams', 'Green', 'Brown', 'Simpson', 'Peters'],\n",
    "                      index=['Tom', 'Niko', 'Penelope', 'Aria', 'Sofia', 'Dean', 'Zach'])\n",
    "last_name"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's try that assignment again. This technically will overwrite our previous **`LAST NAME`** column"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>GENDER</th>\n",
       "      <th>RACE</th>\n",
       "      <th>DEPARTMENT</th>\n",
       "      <th>YEARS EXPERIENCE</th>\n",
       "      <th>SALARY</th>\n",
       "      <th>SCORE</th>\n",
       "      <th>BONUS RATE</th>\n",
       "      <th>FLOOR</th>\n",
       "      <th>LAST NAME</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Tom</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>23</td>\n",
       "      <td>107962</td>\n",
       "      <td>99</td>\n",
       "      <td>0.20</td>\n",
       "      <td>9</td>\n",
       "      <td>Smith</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Niko</th>\n",
       "      <td>Male</td>\n",
       "      <td>Black</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>1</td>\n",
       "      <td>30347</td>\n",
       "      <td>99</td>\n",
       "      <td>0.10</td>\n",
       "      <td>4</td>\n",
       "      <td>Jones</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Penelope</th>\n",
       "      <td>Female</td>\n",
       "      <td>White</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>12</td>\n",
       "      <td>60258</td>\n",
       "      <td>99</td>\n",
       "      <td>0.00</td>\n",
       "      <td>6</td>\n",
       "      <td>Williams</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aria</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>8</td>\n",
       "      <td>43618</td>\n",
       "      <td>99</td>\n",
       "      <td>0.15</td>\n",
       "      <td>8</td>\n",
       "      <td>Green</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sofia</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>23</td>\n",
       "      <td>26125</td>\n",
       "      <td>99</td>\n",
       "      <td>0.12</td>\n",
       "      <td>6</td>\n",
       "      <td>Brown</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dean</th>\n",
       "      <td>Male</td>\n",
       "      <td>Black</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>3</td>\n",
       "      <td>33592</td>\n",
       "      <td>99</td>\n",
       "      <td>0.30</td>\n",
       "      <td>8</td>\n",
       "      <td>Simpson</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zach</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>4</td>\n",
       "      <td>37565</td>\n",
       "      <td>99</td>\n",
       "      <td>0.05</td>\n",
       "      <td>7</td>\n",
       "      <td>Peters</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          GENDER   RACE          DEPARTMENT  YEARS EXPERIENCE  SALARY  SCORE  \\\n",
       "Tom         Male  White         Engineering                23  107962     99   \n",
       "Niko        Male  Black         Engineering                 1   30347     99   \n",
       "Penelope  Female  White         Engineering                12   60258     99   \n",
       "Aria      Female  Black         Engineering                 8   43618     99   \n",
       "Sofia     Female  Black  Parks & Recreation                23   26125     99   \n",
       "Dean        Male  Black  Parks & Recreation                 3   33592     99   \n",
       "Zach        Male  White  Parks & Recreation                 4   37565     99   \n",
       "\n",
       "          BONUS RATE  FLOOR LAST NAME  \n",
       "Tom             0.20      9     Smith  \n",
       "Niko            0.10      4     Jones  \n",
       "Penelope        0.00      6  Williams  \n",
       "Aria            0.15      8     Green  \n",
       "Sofia           0.12      6     Brown  \n",
       "Dean            0.30      8   Simpson  \n",
       "Zach            0.05      7    Peters  "
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['LAST NAME'] = last_name\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Create a new column with expressions involving other columns\n",
    "We can create a new column by combining any number of other columns. One primary way of doing that is through a mathematical expression. For instance, let's create a new column **`BONUS`** by multiplying the **`BONUS RATE`** and **`SALARY`** columns together.\n",
    "\n",
    "## Output before assignment\n",
    "Before adding this new column to your DataFrame, you might want to consider viewing the output before making the assignment. This gives you a little preview so that you can check your work before doing the more permanent assignment.\n",
    "\n",
    "Let's multiple our two columns without assignment:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Tom         21592.40\n",
       "Niko         3034.70\n",
       "Penelope        0.00\n",
       "Aria         6542.70\n",
       "Sofia        3135.00\n",
       "Dean        10077.60\n",
       "Zach         1878.25\n",
       "dtype: float64"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['BONUS RATE'] * df['SALARY']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Everything appears to be OK, so go ahead and make the assignment. Notice that the output is a Series with index the same as the DataFrame."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>GENDER</th>\n",
       "      <th>RACE</th>\n",
       "      <th>DEPARTMENT</th>\n",
       "      <th>YEARS EXPERIENCE</th>\n",
       "      <th>SALARY</th>\n",
       "      <th>SCORE</th>\n",
       "      <th>BONUS RATE</th>\n",
       "      <th>FLOOR</th>\n",
       "      <th>LAST NAME</th>\n",
       "      <th>BONUS</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Tom</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>23</td>\n",
       "      <td>107962</td>\n",
       "      <td>99</td>\n",
       "      <td>0.20</td>\n",
       "      <td>9</td>\n",
       "      <td>Smith</td>\n",
       "      <td>21592.40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Niko</th>\n",
       "      <td>Male</td>\n",
       "      <td>Black</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>1</td>\n",
       "      <td>30347</td>\n",
       "      <td>99</td>\n",
       "      <td>0.10</td>\n",
       "      <td>4</td>\n",
       "      <td>Jones</td>\n",
       "      <td>3034.70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Penelope</th>\n",
       "      <td>Female</td>\n",
       "      <td>White</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>12</td>\n",
       "      <td>60258</td>\n",
       "      <td>99</td>\n",
       "      <td>0.00</td>\n",
       "      <td>6</td>\n",
       "      <td>Williams</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aria</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>8</td>\n",
       "      <td>43618</td>\n",
       "      <td>99</td>\n",
       "      <td>0.15</td>\n",
       "      <td>8</td>\n",
       "      <td>Green</td>\n",
       "      <td>6542.70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sofia</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>23</td>\n",
       "      <td>26125</td>\n",
       "      <td>99</td>\n",
       "      <td>0.12</td>\n",
       "      <td>6</td>\n",
       "      <td>Brown</td>\n",
       "      <td>3135.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dean</th>\n",
       "      <td>Male</td>\n",
       "      <td>Black</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>3</td>\n",
       "      <td>33592</td>\n",
       "      <td>99</td>\n",
       "      <td>0.30</td>\n",
       "      <td>8</td>\n",
       "      <td>Simpson</td>\n",
       "      <td>10077.60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zach</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>4</td>\n",
       "      <td>37565</td>\n",
       "      <td>99</td>\n",
       "      <td>0.05</td>\n",
       "      <td>7</td>\n",
       "      <td>Peters</td>\n",
       "      <td>1878.25</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          GENDER   RACE          DEPARTMENT  YEARS EXPERIENCE  SALARY  SCORE  \\\n",
       "Tom         Male  White         Engineering                23  107962     99   \n",
       "Niko        Male  Black         Engineering                 1   30347     99   \n",
       "Penelope  Female  White         Engineering                12   60258     99   \n",
       "Aria      Female  Black         Engineering                 8   43618     99   \n",
       "Sofia     Female  Black  Parks & Recreation                23   26125     99   \n",
       "Dean        Male  Black  Parks & Recreation                 3   33592     99   \n",
       "Zach        Male  White  Parks & Recreation                 4   37565     99   \n",
       "\n",
       "          BONUS RATE  FLOOR LAST NAME     BONUS  \n",
       "Tom             0.20      9     Smith  21592.40  \n",
       "Niko            0.10      4     Jones   3034.70  \n",
       "Penelope        0.00      6  Williams      0.00  \n",
       "Aria            0.15      8     Green   6542.70  \n",
       "Sofia           0.12      6     Brown   3135.00  \n",
       "Dean            0.30      8   Simpson  10077.60  \n",
       "Zach            0.05      7    Peters   1878.25  "
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['BONUS'] = df['BONUS RATE'] * df['SALARY']\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Actual Subset Assignment\n",
    "So far, we have just added new columns to our DataFrame. We did not change any of the pre-existing values. Let's begin doing this by changing each person's **`SCORE`** to 100.\n",
    "\n",
    "The syntax is the same, whether it's adding a new column or changing an existing column:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>GENDER</th>\n",
       "      <th>RACE</th>\n",
       "      <th>DEPARTMENT</th>\n",
       "      <th>YEARS EXPERIENCE</th>\n",
       "      <th>SALARY</th>\n",
       "      <th>SCORE</th>\n",
       "      <th>BONUS RATE</th>\n",
       "      <th>FLOOR</th>\n",
       "      <th>LAST NAME</th>\n",
       "      <th>BONUS</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Tom</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>23</td>\n",
       "      <td>107962</td>\n",
       "      <td>100</td>\n",
       "      <td>0.20</td>\n",
       "      <td>9</td>\n",
       "      <td>Smith</td>\n",
       "      <td>21592.40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Niko</th>\n",
       "      <td>Male</td>\n",
       "      <td>Black</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>1</td>\n",
       "      <td>30347</td>\n",
       "      <td>100</td>\n",
       "      <td>0.10</td>\n",
       "      <td>4</td>\n",
       "      <td>Jones</td>\n",
       "      <td>3034.70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Penelope</th>\n",
       "      <td>Female</td>\n",
       "      <td>White</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>12</td>\n",
       "      <td>60258</td>\n",
       "      <td>100</td>\n",
       "      <td>0.00</td>\n",
       "      <td>6</td>\n",
       "      <td>Williams</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aria</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>8</td>\n",
       "      <td>43618</td>\n",
       "      <td>100</td>\n",
       "      <td>0.15</td>\n",
       "      <td>8</td>\n",
       "      <td>Green</td>\n",
       "      <td>6542.70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sofia</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>23</td>\n",
       "      <td>26125</td>\n",
       "      <td>100</td>\n",
       "      <td>0.12</td>\n",
       "      <td>6</td>\n",
       "      <td>Brown</td>\n",
       "      <td>3135.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dean</th>\n",
       "      <td>Male</td>\n",
       "      <td>Black</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>3</td>\n",
       "      <td>33592</td>\n",
       "      <td>100</td>\n",
       "      <td>0.30</td>\n",
       "      <td>8</td>\n",
       "      <td>Simpson</td>\n",
       "      <td>10077.60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zach</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>4</td>\n",
       "      <td>37565</td>\n",
       "      <td>100</td>\n",
       "      <td>0.05</td>\n",
       "      <td>7</td>\n",
       "      <td>Peters</td>\n",
       "      <td>1878.25</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          GENDER   RACE          DEPARTMENT  YEARS EXPERIENCE  SALARY  SCORE  \\\n",
       "Tom         Male  White         Engineering                23  107962    100   \n",
       "Niko        Male  Black         Engineering                 1   30347    100   \n",
       "Penelope  Female  White         Engineering                12   60258    100   \n",
       "Aria      Female  Black         Engineering                 8   43618    100   \n",
       "Sofia     Female  Black  Parks & Recreation                23   26125    100   \n",
       "Dean        Male  Black  Parks & Recreation                 3   33592    100   \n",
       "Zach        Male  White  Parks & Recreation                 4   37565    100   \n",
       "\n",
       "          BONUS RATE  FLOOR LAST NAME     BONUS  \n",
       "Tom             0.20      9     Smith  21592.40  \n",
       "Niko            0.10      4     Jones   3034.70  \n",
       "Penelope        0.00      6  Williams      0.00  \n",
       "Aria            0.15      8     Green   6542.70  \n",
       "Sofia           0.12      6     Brown   3135.00  \n",
       "Dean            0.30      8   Simpson  10077.60  \n",
       "Zach            0.05      7    Peters   1878.25  "
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['SCORE'] = 100\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Overwriting the same column\n",
    "You can use the column itself you are assigning in the expression on the right-hand side of the equal sign. For instance, if we want to remove the ugly decimals from the **`BONUS`** column, we can call the **`astype`** method on it and assign it to itself."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>GENDER</th>\n",
       "      <th>RACE</th>\n",
       "      <th>DEPARTMENT</th>\n",
       "      <th>YEARS EXPERIENCE</th>\n",
       "      <th>SALARY</th>\n",
       "      <th>SCORE</th>\n",
       "      <th>BONUS RATE</th>\n",
       "      <th>FLOOR</th>\n",
       "      <th>LAST NAME</th>\n",
       "      <th>BONUS</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Tom</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>23</td>\n",
       "      <td>107962</td>\n",
       "      <td>100</td>\n",
       "      <td>0.20</td>\n",
       "      <td>9</td>\n",
       "      <td>Smith</td>\n",
       "      <td>21592</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Niko</th>\n",
       "      <td>Male</td>\n",
       "      <td>Black</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>1</td>\n",
       "      <td>30347</td>\n",
       "      <td>100</td>\n",
       "      <td>0.10</td>\n",
       "      <td>4</td>\n",
       "      <td>Jones</td>\n",
       "      <td>3034</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Penelope</th>\n",
       "      <td>Female</td>\n",
       "      <td>White</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>12</td>\n",
       "      <td>60258</td>\n",
       "      <td>100</td>\n",
       "      <td>0.00</td>\n",
       "      <td>6</td>\n",
       "      <td>Williams</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aria</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>8</td>\n",
       "      <td>43618</td>\n",
       "      <td>100</td>\n",
       "      <td>0.15</td>\n",
       "      <td>8</td>\n",
       "      <td>Green</td>\n",
       "      <td>6542</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sofia</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>23</td>\n",
       "      <td>26125</td>\n",
       "      <td>100</td>\n",
       "      <td>0.12</td>\n",
       "      <td>6</td>\n",
       "      <td>Brown</td>\n",
       "      <td>3135</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dean</th>\n",
       "      <td>Male</td>\n",
       "      <td>Black</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>3</td>\n",
       "      <td>33592</td>\n",
       "      <td>100</td>\n",
       "      <td>0.30</td>\n",
       "      <td>8</td>\n",
       "      <td>Simpson</td>\n",
       "      <td>10077</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zach</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>4</td>\n",
       "      <td>37565</td>\n",
       "      <td>100</td>\n",
       "      <td>0.05</td>\n",
       "      <td>7</td>\n",
       "      <td>Peters</td>\n",
       "      <td>1878</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          GENDER   RACE          DEPARTMENT  YEARS EXPERIENCE  SALARY  SCORE  \\\n",
       "Tom         Male  White         Engineering                23  107962    100   \n",
       "Niko        Male  Black         Engineering                 1   30347    100   \n",
       "Penelope  Female  White         Engineering                12   60258    100   \n",
       "Aria      Female  Black         Engineering                 8   43618    100   \n",
       "Sofia     Female  Black  Parks & Recreation                23   26125    100   \n",
       "Dean        Male  Black  Parks & Recreation                 3   33592    100   \n",
       "Zach        Male  White  Parks & Recreation                 4   37565    100   \n",
       "\n",
       "          BONUS RATE  FLOOR LAST NAME  BONUS  \n",
       "Tom             0.20      9     Smith  21592  \n",
       "Niko            0.10      4     Jones   3034  \n",
       "Penelope        0.00      6  Williams      0  \n",
       "Aria            0.15      8     Green   6542  \n",
       "Sofia           0.12      6     Brown   3135  \n",
       "Dean            0.30      8   Simpson  10077  \n",
       "Zach            0.05      7    Peters   1878  "
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['BONUS'] = df['BONUS'].astype(int)\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Assigning a subset of rows within a single column\n",
    "Now that we can change all the values in a single at once, let's learn how to change just a subset of them.\n",
    "\n",
    "For instance, let's change the **`FLOOR`** for **`Niko`**, **`Penelope`**, and **`Aria`**. Before doing so, let's remember how to make that subset selection with **`.loc`**:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Niko        4\n",
       "Penelope    6\n",
       "Aria        8\n",
       "Name: FLOOR, dtype: int64"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[['Niko', 'Penelope', 'Aria'], 'FLOOR']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The **`.loc`** indexer allows for row and column selection separated by a comma. It only makes selections based on row/column **labels**. Once we have correctly selected our subset, let's assign it a list of three new integers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>GENDER</th>\n",
       "      <th>RACE</th>\n",
       "      <th>DEPARTMENT</th>\n",
       "      <th>YEARS EXPERIENCE</th>\n",
       "      <th>SALARY</th>\n",
       "      <th>SCORE</th>\n",
       "      <th>BONUS RATE</th>\n",
       "      <th>FLOOR</th>\n",
       "      <th>LAST NAME</th>\n",
       "      <th>BONUS</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Tom</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>23</td>\n",
       "      <td>107962</td>\n",
       "      <td>100</td>\n",
       "      <td>0.20</td>\n",
       "      <td>9</td>\n",
       "      <td>Smith</td>\n",
       "      <td>21592</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Niko</th>\n",
       "      <td>Male</td>\n",
       "      <td>Black</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>1</td>\n",
       "      <td>30347</td>\n",
       "      <td>100</td>\n",
       "      <td>0.10</td>\n",
       "      <td>3</td>\n",
       "      <td>Jones</td>\n",
       "      <td>3034</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Penelope</th>\n",
       "      <td>Female</td>\n",
       "      <td>White</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>12</td>\n",
       "      <td>60258</td>\n",
       "      <td>100</td>\n",
       "      <td>0.00</td>\n",
       "      <td>6</td>\n",
       "      <td>Williams</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aria</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>8</td>\n",
       "      <td>43618</td>\n",
       "      <td>100</td>\n",
       "      <td>0.15</td>\n",
       "      <td>4</td>\n",
       "      <td>Green</td>\n",
       "      <td>6542</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sofia</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>23</td>\n",
       "      <td>26125</td>\n",
       "      <td>100</td>\n",
       "      <td>0.12</td>\n",
       "      <td>6</td>\n",
       "      <td>Brown</td>\n",
       "      <td>3135</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dean</th>\n",
       "      <td>Male</td>\n",
       "      <td>Black</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>3</td>\n",
       "      <td>33592</td>\n",
       "      <td>100</td>\n",
       "      <td>0.30</td>\n",
       "      <td>8</td>\n",
       "      <td>Simpson</td>\n",
       "      <td>10077</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zach</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>4</td>\n",
       "      <td>37565</td>\n",
       "      <td>100</td>\n",
       "      <td>0.05</td>\n",
       "      <td>7</td>\n",
       "      <td>Peters</td>\n",
       "      <td>1878</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          GENDER   RACE          DEPARTMENT  YEARS EXPERIENCE  SALARY  SCORE  \\\n",
       "Tom         Male  White         Engineering                23  107962    100   \n",
       "Niko        Male  Black         Engineering                 1   30347    100   \n",
       "Penelope  Female  White         Engineering                12   60258    100   \n",
       "Aria      Female  Black         Engineering                 8   43618    100   \n",
       "Sofia     Female  Black  Parks & Recreation                23   26125    100   \n",
       "Dean        Male  Black  Parks & Recreation                 3   33592    100   \n",
       "Zach        Male  White  Parks & Recreation                 4   37565    100   \n",
       "\n",
       "          BONUS RATE  FLOOR LAST NAME  BONUS  \n",
       "Tom             0.20      9     Smith  21592  \n",
       "Niko            0.10      3     Jones   3034  \n",
       "Penelope        0.00      6  Williams      0  \n",
       "Aria            0.15      4     Green   6542  \n",
       "Sofia           0.12      6     Brown   3135  \n",
       "Dean            0.30      8   Simpson  10077  \n",
       "Zach            0.05      7    Peters   1878  "
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[['Niko', 'Penelope', 'Aria'], 'FLOOR'] = [3, 6, 4]\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Style DataFrame to show differences (advanced)\n",
    "It's not important you understand this section if you are new to pandas, but you should still read through it as the **`style_diff`** function will be used in subsequent sections. Pandas provides a **`style`** attribute which allows you to apply a wide variety of CSS styles to your DataFrames. Check the [style documentation](http://pandas.pydata.org/pandas-docs/stable/style.html) for more.\n",
    "\n",
    "We are going to change the background color and the color of the text for the values that have changed. To do this, you need to create a copy of the DataFrame before you make any changes with the **`copy`** method."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "df_orig = df.copy()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Then, we make our changes to our DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>GENDER</th>\n",
       "      <th>RACE</th>\n",
       "      <th>DEPARTMENT</th>\n",
       "      <th>YEARS EXPERIENCE</th>\n",
       "      <th>SALARY</th>\n",
       "      <th>SCORE</th>\n",
       "      <th>BONUS RATE</th>\n",
       "      <th>FLOOR</th>\n",
       "      <th>LAST NAME</th>\n",
       "      <th>BONUS</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Tom</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>23</td>\n",
       "      <td>107962</td>\n",
       "      <td>100</td>\n",
       "      <td>0.20</td>\n",
       "      <td>9</td>\n",
       "      <td>Smith</td>\n",
       "      <td>21592</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Niko</th>\n",
       "      <td>Male</td>\n",
       "      <td>Black</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>1</td>\n",
       "      <td>30347</td>\n",
       "      <td>100</td>\n",
       "      <td>0.10</td>\n",
       "      <td>60</td>\n",
       "      <td>Jones</td>\n",
       "      <td>3034</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Penelope</th>\n",
       "      <td>Female</td>\n",
       "      <td>White</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>12</td>\n",
       "      <td>60258</td>\n",
       "      <td>100</td>\n",
       "      <td>0.00</td>\n",
       "      <td>42</td>\n",
       "      <td>Williams</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aria</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>8</td>\n",
       "      <td>43618</td>\n",
       "      <td>100</td>\n",
       "      <td>0.15</td>\n",
       "      <td>99</td>\n",
       "      <td>Green</td>\n",
       "      <td>6542</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sofia</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>23</td>\n",
       "      <td>26125</td>\n",
       "      <td>100</td>\n",
       "      <td>0.12</td>\n",
       "      <td>6</td>\n",
       "      <td>Brown</td>\n",
       "      <td>3135</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dean</th>\n",
       "      <td>Male</td>\n",
       "      <td>Black</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>3</td>\n",
       "      <td>33592</td>\n",
       "      <td>100</td>\n",
       "      <td>0.30</td>\n",
       "      <td>8</td>\n",
       "      <td>Simpson</td>\n",
       "      <td>10077</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zach</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>4</td>\n",
       "      <td>37565</td>\n",
       "      <td>100</td>\n",
       "      <td>0.05</td>\n",
       "      <td>7</td>\n",
       "      <td>Peters</td>\n",
       "      <td>1878</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          GENDER   RACE          DEPARTMENT  YEARS EXPERIENCE  SALARY  SCORE  \\\n",
       "Tom         Male  White         Engineering                23  107962    100   \n",
       "Niko        Male  Black         Engineering                 1   30347    100   \n",
       "Penelope  Female  White         Engineering                12   60258    100   \n",
       "Aria      Female  Black         Engineering                 8   43618    100   \n",
       "Sofia     Female  Black  Parks & Recreation                23   26125    100   \n",
       "Dean        Male  Black  Parks & Recreation                 3   33592    100   \n",
       "Zach        Male  White  Parks & Recreation                 4   37565    100   \n",
       "\n",
       "          BONUS RATE  FLOOR LAST NAME  BONUS  \n",
       "Tom             0.20      9     Smith  21592  \n",
       "Niko            0.10     60     Jones   3034  \n",
       "Penelope        0.00     42  Williams      0  \n",
       "Aria            0.15     99     Green   6542  \n",
       "Sofia           0.12      6     Brown   3135  \n",
       "Dean            0.30      8   Simpson  10077  \n",
       "Zach            0.05      7    Peters   1878  "
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[['Niko', 'Penelope', 'Aria'], 'FLOOR'] = [60, 42, 99]\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can see that the values have changed, but it would be a bit nicer if they stood out more. The function below accepts the entire DataFrame for parameter **`x`** and the original as **`orig`**. It then creates a boolean DataFrame and replaces all the **`False`** values with a semi-colon separated list of new CSS table **`attribute: value`** pairs."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def style_diff(df, df_orig):\n",
    "    style = {True: '', \n",
    "             False: 'color: red; background-color: yellow'}\n",
    "    df_style = (df == df_orig).replace(style)\n",
    "    return df.style.apply(lambda x: df_style, axis=None)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can use this function with any DataFrame that we have. But, take care when using a large DataFrame as the style DataFrames **output every single row**. So, if you have a 10,000 row DataFrame, you are probably going to crash your notebook."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style  type=\"text/css\" >\n",
       "    #T_e51b4f50_dece_11e7_a929_b8e85647e68crow1_col7 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }    #T_e51b4f50_dece_11e7_a929_b8e85647e68crow2_col7 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }    #T_e51b4f50_dece_11e7_a929_b8e85647e68crow3_col7 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }</style>  \n",
       "<table id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68c\" > \n",
       "<thead>    <tr> \n",
       "        <th class=\"blank level0\" ></th> \n",
       "        <th class=\"col_heading level0 col0\" >GENDER</th> \n",
       "        <th class=\"col_heading level0 col1\" >RACE</th> \n",
       "        <th class=\"col_heading level0 col2\" >DEPARTMENT</th> \n",
       "        <th class=\"col_heading level0 col3\" >YEARS EXPERIENCE</th> \n",
       "        <th class=\"col_heading level0 col4\" >SALARY</th> \n",
       "        <th class=\"col_heading level0 col5\" >SCORE</th> \n",
       "        <th class=\"col_heading level0 col6\" >BONUS RATE</th> \n",
       "        <th class=\"col_heading level0 col7\" >FLOOR</th> \n",
       "        <th class=\"col_heading level0 col8\" >LAST NAME</th> \n",
       "        <th class=\"col_heading level0 col9\" >BONUS</th> \n",
       "    </tr></thead> \n",
       "<tbody>    <tr> \n",
       "        <th id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68clevel0_row0\" class=\"row_heading level0 row0\" >Tom</th> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow0_col0\" class=\"data row0 col0\" >Male</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow0_col1\" class=\"data row0 col1\" >White</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow0_col2\" class=\"data row0 col2\" >Engineering</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow0_col3\" class=\"data row0 col3\" >23</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow0_col4\" class=\"data row0 col4\" >107962</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow0_col5\" class=\"data row0 col5\" >100</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow0_col6\" class=\"data row0 col6\" >0.2</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow0_col7\" class=\"data row0 col7\" >9</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow0_col8\" class=\"data row0 col8\" >Smith</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow0_col9\" class=\"data row0 col9\" >21592</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68clevel0_row1\" class=\"row_heading level0 row1\" >Niko</th> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow1_col0\" class=\"data row1 col0\" >Male</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow1_col1\" class=\"data row1 col1\" >Black</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow1_col2\" class=\"data row1 col2\" >Engineering</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow1_col3\" class=\"data row1 col3\" >1</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow1_col4\" class=\"data row1 col4\" >30347</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow1_col5\" class=\"data row1 col5\" >100</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow1_col6\" class=\"data row1 col6\" >0.1</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow1_col7\" class=\"data row1 col7\" >60</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow1_col8\" class=\"data row1 col8\" >Jones</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow1_col9\" class=\"data row1 col9\" >3034</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68clevel0_row2\" class=\"row_heading level0 row2\" >Penelope</th> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow2_col0\" class=\"data row2 col0\" >Female</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow2_col1\" class=\"data row2 col1\" >White</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow2_col2\" class=\"data row2 col2\" >Engineering</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow2_col3\" class=\"data row2 col3\" >12</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow2_col4\" class=\"data row2 col4\" >60258</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow2_col5\" class=\"data row2 col5\" >100</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow2_col6\" class=\"data row2 col6\" >0</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow2_col7\" class=\"data row2 col7\" >42</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow2_col8\" class=\"data row2 col8\" >Williams</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow2_col9\" class=\"data row2 col9\" >0</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68clevel0_row3\" class=\"row_heading level0 row3\" >Aria</th> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow3_col0\" class=\"data row3 col0\" >Female</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow3_col1\" class=\"data row3 col1\" >Black</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow3_col2\" class=\"data row3 col2\" >Engineering</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow3_col3\" class=\"data row3 col3\" >8</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow3_col4\" class=\"data row3 col4\" >43618</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow3_col5\" class=\"data row3 col5\" >100</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow3_col6\" class=\"data row3 col6\" >0.15</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow3_col7\" class=\"data row3 col7\" >99</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow3_col8\" class=\"data row3 col8\" >Green</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow3_col9\" class=\"data row3 col9\" >6542</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68clevel0_row4\" class=\"row_heading level0 row4\" >Sofia</th> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow4_col0\" class=\"data row4 col0\" >Female</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow4_col1\" class=\"data row4 col1\" >Black</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow4_col2\" class=\"data row4 col2\" >Parks & Recreation</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow4_col3\" class=\"data row4 col3\" >23</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow4_col4\" class=\"data row4 col4\" >26125</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow4_col5\" class=\"data row4 col5\" >100</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow4_col6\" class=\"data row4 col6\" >0.12</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow4_col7\" class=\"data row4 col7\" >6</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow4_col8\" class=\"data row4 col8\" >Brown</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow4_col9\" class=\"data row4 col9\" >3135</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68clevel0_row5\" class=\"row_heading level0 row5\" >Dean</th> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow5_col0\" class=\"data row5 col0\" >Male</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow5_col1\" class=\"data row5 col1\" >Black</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow5_col2\" class=\"data row5 col2\" >Parks & Recreation</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow5_col3\" class=\"data row5 col3\" >3</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow5_col4\" class=\"data row5 col4\" >33592</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow5_col5\" class=\"data row5 col5\" >100</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow5_col6\" class=\"data row5 col6\" >0.3</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow5_col7\" class=\"data row5 col7\" >8</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow5_col8\" class=\"data row5 col8\" >Simpson</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow5_col9\" class=\"data row5 col9\" >10077</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68clevel0_row6\" class=\"row_heading level0 row6\" >Zach</th> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow6_col0\" class=\"data row6 col0\" >Male</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow6_col1\" class=\"data row6 col1\" >White</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow6_col2\" class=\"data row6 col2\" >Parks & Recreation</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow6_col3\" class=\"data row6 col3\" >4</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow6_col4\" class=\"data row6 col4\" >37565</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow6_col5\" class=\"data row6 col5\" >100</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow6_col6\" class=\"data row6 col6\" >0.05</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow6_col7\" class=\"data row6 col7\" >7</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow6_col8\" class=\"data row6 col8\" >Peters</td> \n",
       "        <td id=\"T_e51b4f50_dece_11e7_a929_b8e85647e68crow6_col9\" class=\"data row6 col9\" >1878</td> \n",
       "    </tr></tbody> \n",
       "</table> "
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x106d32da0>"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "style_diff(df, df_orig)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Assigning subsets with `.iloc`\n",
    "Similarly, we can use the **`.iloc`** indexer which only makes selections via **`integer location`**.\n",
    "\n",
    "Let's assign the 3rd - 6th rows of the **`SCORE`** column (integer location 5) with the value 99. Again, we will make a copy of the DataFrame and display the difference with our **`style_diff`** function."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "df_orig = df.copy()\n",
    "\n",
    "df.iloc[3:6, 5] = 99"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style  type=\"text/css\" >\n",
       "    #T_e5226a1a_dece_11e7_804c_b8e85647e68crow3_col5 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }    #T_e5226a1a_dece_11e7_804c_b8e85647e68crow4_col5 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }    #T_e5226a1a_dece_11e7_804c_b8e85647e68crow5_col5 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }</style>  \n",
       "<table id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68c\" > \n",
       "<thead>    <tr> \n",
       "        <th class=\"blank level0\" ></th> \n",
       "        <th class=\"col_heading level0 col0\" >GENDER</th> \n",
       "        <th class=\"col_heading level0 col1\" >RACE</th> \n",
       "        <th class=\"col_heading level0 col2\" >DEPARTMENT</th> \n",
       "        <th class=\"col_heading level0 col3\" >YEARS EXPERIENCE</th> \n",
       "        <th class=\"col_heading level0 col4\" >SALARY</th> \n",
       "        <th class=\"col_heading level0 col5\" >SCORE</th> \n",
       "        <th class=\"col_heading level0 col6\" >BONUS RATE</th> \n",
       "        <th class=\"col_heading level0 col7\" >FLOOR</th> \n",
       "        <th class=\"col_heading level0 col8\" >LAST NAME</th> \n",
       "        <th class=\"col_heading level0 col9\" >BONUS</th> \n",
       "    </tr></thead> \n",
       "<tbody>    <tr> \n",
       "        <th id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68clevel0_row0\" class=\"row_heading level0 row0\" >Tom</th> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow0_col0\" class=\"data row0 col0\" >Male</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow0_col1\" class=\"data row0 col1\" >White</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow0_col2\" class=\"data row0 col2\" >Engineering</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow0_col3\" class=\"data row0 col3\" >23</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow0_col4\" class=\"data row0 col4\" >107962</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow0_col5\" class=\"data row0 col5\" >100</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow0_col6\" class=\"data row0 col6\" >0.2</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow0_col7\" class=\"data row0 col7\" >9</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow0_col8\" class=\"data row0 col8\" >Smith</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow0_col9\" class=\"data row0 col9\" >21592</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68clevel0_row1\" class=\"row_heading level0 row1\" >Niko</th> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow1_col0\" class=\"data row1 col0\" >Male</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow1_col1\" class=\"data row1 col1\" >Black</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow1_col2\" class=\"data row1 col2\" >Engineering</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow1_col3\" class=\"data row1 col3\" >1</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow1_col4\" class=\"data row1 col4\" >30347</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow1_col5\" class=\"data row1 col5\" >100</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow1_col6\" class=\"data row1 col6\" >0.1</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow1_col7\" class=\"data row1 col7\" >60</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow1_col8\" class=\"data row1 col8\" >Jones</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow1_col9\" class=\"data row1 col9\" >3034</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68clevel0_row2\" class=\"row_heading level0 row2\" >Penelope</th> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow2_col0\" class=\"data row2 col0\" >Female</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow2_col1\" class=\"data row2 col1\" >White</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow2_col2\" class=\"data row2 col2\" >Engineering</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow2_col3\" class=\"data row2 col3\" >12</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow2_col4\" class=\"data row2 col4\" >60258</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow2_col5\" class=\"data row2 col5\" >100</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow2_col6\" class=\"data row2 col6\" >0</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow2_col7\" class=\"data row2 col7\" >42</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow2_col8\" class=\"data row2 col8\" >Williams</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow2_col9\" class=\"data row2 col9\" >0</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68clevel0_row3\" class=\"row_heading level0 row3\" >Aria</th> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow3_col0\" class=\"data row3 col0\" >Female</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow3_col1\" class=\"data row3 col1\" >Black</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow3_col2\" class=\"data row3 col2\" >Engineering</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow3_col3\" class=\"data row3 col3\" >8</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow3_col4\" class=\"data row3 col4\" >43618</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow3_col5\" class=\"data row3 col5\" >99</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow3_col6\" class=\"data row3 col6\" >0.15</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow3_col7\" class=\"data row3 col7\" >99</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow3_col8\" class=\"data row3 col8\" >Green</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow3_col9\" class=\"data row3 col9\" >6542</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68clevel0_row4\" class=\"row_heading level0 row4\" >Sofia</th> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow4_col0\" class=\"data row4 col0\" >Female</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow4_col1\" class=\"data row4 col1\" >Black</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow4_col2\" class=\"data row4 col2\" >Parks & Recreation</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow4_col3\" class=\"data row4 col3\" >23</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow4_col4\" class=\"data row4 col4\" >26125</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow4_col5\" class=\"data row4 col5\" >99</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow4_col6\" class=\"data row4 col6\" >0.12</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow4_col7\" class=\"data row4 col7\" >6</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow4_col8\" class=\"data row4 col8\" >Brown</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow4_col9\" class=\"data row4 col9\" >3135</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68clevel0_row5\" class=\"row_heading level0 row5\" >Dean</th> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow5_col0\" class=\"data row5 col0\" >Male</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow5_col1\" class=\"data row5 col1\" >Black</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow5_col2\" class=\"data row5 col2\" >Parks & Recreation</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow5_col3\" class=\"data row5 col3\" >3</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow5_col4\" class=\"data row5 col4\" >33592</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow5_col5\" class=\"data row5 col5\" >99</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow5_col6\" class=\"data row5 col6\" >0.3</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow5_col7\" class=\"data row5 col7\" >8</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow5_col8\" class=\"data row5 col8\" >Simpson</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow5_col9\" class=\"data row5 col9\" >10077</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68clevel0_row6\" class=\"row_heading level0 row6\" >Zach</th> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow6_col0\" class=\"data row6 col0\" >Male</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow6_col1\" class=\"data row6 col1\" >White</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow6_col2\" class=\"data row6 col2\" >Parks & Recreation</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow6_col3\" class=\"data row6 col3\" >4</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow6_col4\" class=\"data row6 col4\" >37565</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow6_col5\" class=\"data row6 col5\" >100</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow6_col6\" class=\"data row6 col6\" >0.05</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow6_col7\" class=\"data row6 col7\" >7</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow6_col8\" class=\"data row6 col8\" >Peters</td> \n",
       "        <td id=\"T_e5226a1a_dece_11e7_804c_b8e85647e68crow6_col9\" class=\"data row6 col9\" >1878</td> \n",
       "    </tr></tbody> \n",
       "</table> "
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x106d32c88>"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "style_diff(df, df_orig)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Assigning an entire column with `.loc` and `.iloc`\n",
    "Normally, *just the indexing operator* is used to change values of an entire column, but it's also possible to do it with both **`.loc`** and **.`iloc`**. You have to remember that the fist selection made by both these indexers is the rows. To select all rows, use the colon **`:`**.\n",
    "\n",
    "For instance, let's see this in action by changing all values in the **`FLOOR`** column."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style  type=\"text/css\" >\n",
       "    #T_e527972e_dece_11e7_b313_b8e85647e68crow0_col7 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }    #T_e527972e_dece_11e7_b313_b8e85647e68crow1_col7 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }    #T_e527972e_dece_11e7_b313_b8e85647e68crow2_col7 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }    #T_e527972e_dece_11e7_b313_b8e85647e68crow3_col7 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }    #T_e527972e_dece_11e7_b313_b8e85647e68crow4_col7 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }    #T_e527972e_dece_11e7_b313_b8e85647e68crow5_col7 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }    #T_e527972e_dece_11e7_b313_b8e85647e68crow6_col7 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }</style>  \n",
       "<table id=\"T_e527972e_dece_11e7_b313_b8e85647e68c\" > \n",
       "<thead>    <tr> \n",
       "        <th class=\"blank level0\" ></th> \n",
       "        <th class=\"col_heading level0 col0\" >GENDER</th> \n",
       "        <th class=\"col_heading level0 col1\" >RACE</th> \n",
       "        <th class=\"col_heading level0 col2\" >DEPARTMENT</th> \n",
       "        <th class=\"col_heading level0 col3\" >YEARS EXPERIENCE</th> \n",
       "        <th class=\"col_heading level0 col4\" >SALARY</th> \n",
       "        <th class=\"col_heading level0 col5\" >SCORE</th> \n",
       "        <th class=\"col_heading level0 col6\" >BONUS RATE</th> \n",
       "        <th class=\"col_heading level0 col7\" >FLOOR</th> \n",
       "        <th class=\"col_heading level0 col8\" >LAST NAME</th> \n",
       "        <th class=\"col_heading level0 col9\" >BONUS</th> \n",
       "    </tr></thead> \n",
       "<tbody>    <tr> \n",
       "        <th id=\"T_e527972e_dece_11e7_b313_b8e85647e68clevel0_row0\" class=\"row_heading level0 row0\" >Tom</th> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow0_col0\" class=\"data row0 col0\" >Male</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow0_col1\" class=\"data row0 col1\" >White</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow0_col2\" class=\"data row0 col2\" >Engineering</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow0_col3\" class=\"data row0 col3\" >23</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow0_col4\" class=\"data row0 col4\" >107962</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow0_col5\" class=\"data row0 col5\" >100</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow0_col6\" class=\"data row0 col6\" >0.2</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow0_col7\" class=\"data row0 col7\" >33</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow0_col8\" class=\"data row0 col8\" >Smith</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow0_col9\" class=\"data row0 col9\" >21592</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e527972e_dece_11e7_b313_b8e85647e68clevel0_row1\" class=\"row_heading level0 row1\" >Niko</th> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow1_col0\" class=\"data row1 col0\" >Male</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow1_col1\" class=\"data row1 col1\" >Black</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow1_col2\" class=\"data row1 col2\" >Engineering</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow1_col3\" class=\"data row1 col3\" >1</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow1_col4\" class=\"data row1 col4\" >30347</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow1_col5\" class=\"data row1 col5\" >100</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow1_col6\" class=\"data row1 col6\" >0.1</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow1_col7\" class=\"data row1 col7\" >33</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow1_col8\" class=\"data row1 col8\" >Jones</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow1_col9\" class=\"data row1 col9\" >3034</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e527972e_dece_11e7_b313_b8e85647e68clevel0_row2\" class=\"row_heading level0 row2\" >Penelope</th> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow2_col0\" class=\"data row2 col0\" >Female</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow2_col1\" class=\"data row2 col1\" >White</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow2_col2\" class=\"data row2 col2\" >Engineering</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow2_col3\" class=\"data row2 col3\" >12</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow2_col4\" class=\"data row2 col4\" >60258</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow2_col5\" class=\"data row2 col5\" >100</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow2_col6\" class=\"data row2 col6\" >0</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow2_col7\" class=\"data row2 col7\" >33</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow2_col8\" class=\"data row2 col8\" >Williams</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow2_col9\" class=\"data row2 col9\" >0</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e527972e_dece_11e7_b313_b8e85647e68clevel0_row3\" class=\"row_heading level0 row3\" >Aria</th> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow3_col0\" class=\"data row3 col0\" >Female</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow3_col1\" class=\"data row3 col1\" >Black</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow3_col2\" class=\"data row3 col2\" >Engineering</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow3_col3\" class=\"data row3 col3\" >8</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow3_col4\" class=\"data row3 col4\" >43618</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow3_col5\" class=\"data row3 col5\" >99</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow3_col6\" class=\"data row3 col6\" >0.15</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow3_col7\" class=\"data row3 col7\" >33</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow3_col8\" class=\"data row3 col8\" >Green</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow3_col9\" class=\"data row3 col9\" >6542</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e527972e_dece_11e7_b313_b8e85647e68clevel0_row4\" class=\"row_heading level0 row4\" >Sofia</th> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow4_col0\" class=\"data row4 col0\" >Female</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow4_col1\" class=\"data row4 col1\" >Black</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow4_col2\" class=\"data row4 col2\" >Parks & Recreation</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow4_col3\" class=\"data row4 col3\" >23</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow4_col4\" class=\"data row4 col4\" >26125</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow4_col5\" class=\"data row4 col5\" >99</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow4_col6\" class=\"data row4 col6\" >0.12</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow4_col7\" class=\"data row4 col7\" >33</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow4_col8\" class=\"data row4 col8\" >Brown</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow4_col9\" class=\"data row4 col9\" >3135</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e527972e_dece_11e7_b313_b8e85647e68clevel0_row5\" class=\"row_heading level0 row5\" >Dean</th> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow5_col0\" class=\"data row5 col0\" >Male</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow5_col1\" class=\"data row5 col1\" >Black</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow5_col2\" class=\"data row5 col2\" >Parks & Recreation</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow5_col3\" class=\"data row5 col3\" >3</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow5_col4\" class=\"data row5 col4\" >33592</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow5_col5\" class=\"data row5 col5\" >99</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow5_col6\" class=\"data row5 col6\" >0.3</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow5_col7\" class=\"data row5 col7\" >33</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow5_col8\" class=\"data row5 col8\" >Simpson</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow5_col9\" class=\"data row5 col9\" >10077</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e527972e_dece_11e7_b313_b8e85647e68clevel0_row6\" class=\"row_heading level0 row6\" >Zach</th> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow6_col0\" class=\"data row6 col0\" >Male</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow6_col1\" class=\"data row6 col1\" >White</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow6_col2\" class=\"data row6 col2\" >Parks & Recreation</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow6_col3\" class=\"data row6 col3\" >4</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow6_col4\" class=\"data row6 col4\" >37565</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow6_col5\" class=\"data row6 col5\" >100</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow6_col6\" class=\"data row6 col6\" >0.05</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow6_col7\" class=\"data row6 col7\" >33</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow6_col8\" class=\"data row6 col8\" >Peters</td> \n",
       "        <td id=\"T_e527972e_dece_11e7_b313_b8e85647e68crow6_col9\" class=\"data row6 col9\" >1878</td> \n",
       "    </tr></tbody> \n",
       "</table> "
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x106e0ac50>"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_orig = df.copy()\n",
    "df.loc[:, 'FLOOR'] = 33\n",
    "style_diff(df, df_orig)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "And with **`.iloc`**:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style  type=\"text/css\" >\n",
       "    #T_e52c0c82_dece_11e7_a940_b8e85647e68crow0_col7 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }    #T_e52c0c82_dece_11e7_a940_b8e85647e68crow1_col7 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }    #T_e52c0c82_dece_11e7_a940_b8e85647e68crow2_col7 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }    #T_e52c0c82_dece_11e7_a940_b8e85647e68crow3_col7 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }    #T_e52c0c82_dece_11e7_a940_b8e85647e68crow4_col7 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }    #T_e52c0c82_dece_11e7_a940_b8e85647e68crow5_col7 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }    #T_e52c0c82_dece_11e7_a940_b8e85647e68crow6_col7 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }</style>  \n",
       "<table id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68c\" > \n",
       "<thead>    <tr> \n",
       "        <th class=\"blank level0\" ></th> \n",
       "        <th class=\"col_heading level0 col0\" >GENDER</th> \n",
       "        <th class=\"col_heading level0 col1\" >RACE</th> \n",
       "        <th class=\"col_heading level0 col2\" >DEPARTMENT</th> \n",
       "        <th class=\"col_heading level0 col3\" >YEARS EXPERIENCE</th> \n",
       "        <th class=\"col_heading level0 col4\" >SALARY</th> \n",
       "        <th class=\"col_heading level0 col5\" >SCORE</th> \n",
       "        <th class=\"col_heading level0 col6\" >BONUS RATE</th> \n",
       "        <th class=\"col_heading level0 col7\" >FLOOR</th> \n",
       "        <th class=\"col_heading level0 col8\" >LAST NAME</th> \n",
       "        <th class=\"col_heading level0 col9\" >BONUS</th> \n",
       "    </tr></thead> \n",
       "<tbody>    <tr> \n",
       "        <th id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68clevel0_row0\" class=\"row_heading level0 row0\" >Tom</th> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow0_col0\" class=\"data row0 col0\" >Male</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow0_col1\" class=\"data row0 col1\" >White</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow0_col2\" class=\"data row0 col2\" >Engineering</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow0_col3\" class=\"data row0 col3\" >23</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow0_col4\" class=\"data row0 col4\" >107962</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow0_col5\" class=\"data row0 col5\" >100</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow0_col6\" class=\"data row0 col6\" >0.2</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow0_col7\" class=\"data row0 col7\" >22</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow0_col8\" class=\"data row0 col8\" >Smith</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow0_col9\" class=\"data row0 col9\" >21592</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68clevel0_row1\" class=\"row_heading level0 row1\" >Niko</th> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow1_col0\" class=\"data row1 col0\" >Male</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow1_col1\" class=\"data row1 col1\" >Black</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow1_col2\" class=\"data row1 col2\" >Engineering</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow1_col3\" class=\"data row1 col3\" >1</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow1_col4\" class=\"data row1 col4\" >30347</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow1_col5\" class=\"data row1 col5\" >100</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow1_col6\" class=\"data row1 col6\" >0.1</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow1_col7\" class=\"data row1 col7\" >22</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow1_col8\" class=\"data row1 col8\" >Jones</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow1_col9\" class=\"data row1 col9\" >3034</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68clevel0_row2\" class=\"row_heading level0 row2\" >Penelope</th> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow2_col0\" class=\"data row2 col0\" >Female</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow2_col1\" class=\"data row2 col1\" >White</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow2_col2\" class=\"data row2 col2\" >Engineering</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow2_col3\" class=\"data row2 col3\" >12</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow2_col4\" class=\"data row2 col4\" >60258</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow2_col5\" class=\"data row2 col5\" >100</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow2_col6\" class=\"data row2 col6\" >0</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow2_col7\" class=\"data row2 col7\" >22</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow2_col8\" class=\"data row2 col8\" >Williams</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow2_col9\" class=\"data row2 col9\" >0</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68clevel0_row3\" class=\"row_heading level0 row3\" >Aria</th> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow3_col0\" class=\"data row3 col0\" >Female</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow3_col1\" class=\"data row3 col1\" >Black</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow3_col2\" class=\"data row3 col2\" >Engineering</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow3_col3\" class=\"data row3 col3\" >8</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow3_col4\" class=\"data row3 col4\" >43618</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow3_col5\" class=\"data row3 col5\" >99</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow3_col6\" class=\"data row3 col6\" >0.15</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow3_col7\" class=\"data row3 col7\" >22</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow3_col8\" class=\"data row3 col8\" >Green</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow3_col9\" class=\"data row3 col9\" >6542</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68clevel0_row4\" class=\"row_heading level0 row4\" >Sofia</th> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow4_col0\" class=\"data row4 col0\" >Female</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow4_col1\" class=\"data row4 col1\" >Black</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow4_col2\" class=\"data row4 col2\" >Parks & Recreation</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow4_col3\" class=\"data row4 col3\" >23</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow4_col4\" class=\"data row4 col4\" >26125</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow4_col5\" class=\"data row4 col5\" >99</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow4_col6\" class=\"data row4 col6\" >0.12</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow4_col7\" class=\"data row4 col7\" >22</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow4_col8\" class=\"data row4 col8\" >Brown</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow4_col9\" class=\"data row4 col9\" >3135</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68clevel0_row5\" class=\"row_heading level0 row5\" >Dean</th> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow5_col0\" class=\"data row5 col0\" >Male</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow5_col1\" class=\"data row5 col1\" >Black</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow5_col2\" class=\"data row5 col2\" >Parks & Recreation</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow5_col3\" class=\"data row5 col3\" >3</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow5_col4\" class=\"data row5 col4\" >33592</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow5_col5\" class=\"data row5 col5\" >99</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow5_col6\" class=\"data row5 col6\" >0.3</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow5_col7\" class=\"data row5 col7\" >22</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow5_col8\" class=\"data row5 col8\" >Simpson</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow5_col9\" class=\"data row5 col9\" >10077</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68clevel0_row6\" class=\"row_heading level0 row6\" >Zach</th> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow6_col0\" class=\"data row6 col0\" >Male</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow6_col1\" class=\"data row6 col1\" >White</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow6_col2\" class=\"data row6 col2\" >Parks & Recreation</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow6_col3\" class=\"data row6 col3\" >4</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow6_col4\" class=\"data row6 col4\" >37565</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow6_col5\" class=\"data row6 col5\" >100</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow6_col6\" class=\"data row6 col6\" >0.05</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow6_col7\" class=\"data row6 col7\" >22</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow6_col8\" class=\"data row6 col8\" >Peters</td> \n",
       "        <td id=\"T_e52c0c82_dece_11e7_a940_b8e85647e68crow6_col9\" class=\"data row6 col9\" >1878</td> \n",
       "    </tr></tbody> \n",
       "</table> "
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x107055438>"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_orig = df.copy()\n",
    "df.iloc[:, 7] = 22\n",
    "style_diff(df, df_orig)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Assigning with boolean selection\n",
    "It is more common to use boolean selection to make assignments to subsets than with directly selecting subsets by label or integer location.\n",
    "\n",
    "For instance, let's say we wanted to give everyone in the engineering department a $5,000 bonus on top of what they already have.\n",
    "\n",
    "Before making the assignment, let's properly select the data with boolean indexing."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Tom         21592\n",
       "Niko         3034\n",
       "Penelope        0\n",
       "Aria         6542\n",
       "Name: BONUS, dtype: int64"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[df['DEPARTMENT'] == 'Engineering', 'BONUS']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Once we have confirmed that our selection works, we can make an assignment. We can use the **`+=`** operator to shorten the syntax considerably, which will assign the value back to itself."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style  type=\"text/css\" >\n",
       "    #T_e5329a02_dece_11e7_9363_b8e85647e68crow0_col9 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }    #T_e5329a02_dece_11e7_9363_b8e85647e68crow1_col9 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }    #T_e5329a02_dece_11e7_9363_b8e85647e68crow2_col9 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }    #T_e5329a02_dece_11e7_9363_b8e85647e68crow3_col9 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }</style>  \n",
       "<table id=\"T_e5329a02_dece_11e7_9363_b8e85647e68c\" > \n",
       "<thead>    <tr> \n",
       "        <th class=\"blank level0\" ></th> \n",
       "        <th class=\"col_heading level0 col0\" >GENDER</th> \n",
       "        <th class=\"col_heading level0 col1\" >RACE</th> \n",
       "        <th class=\"col_heading level0 col2\" >DEPARTMENT</th> \n",
       "        <th class=\"col_heading level0 col3\" >YEARS EXPERIENCE</th> \n",
       "        <th class=\"col_heading level0 col4\" >SALARY</th> \n",
       "        <th class=\"col_heading level0 col5\" >SCORE</th> \n",
       "        <th class=\"col_heading level0 col6\" >BONUS RATE</th> \n",
       "        <th class=\"col_heading level0 col7\" >FLOOR</th> \n",
       "        <th class=\"col_heading level0 col8\" >LAST NAME</th> \n",
       "        <th class=\"col_heading level0 col9\" >BONUS</th> \n",
       "    </tr></thead> \n",
       "<tbody>    <tr> \n",
       "        <th id=\"T_e5329a02_dece_11e7_9363_b8e85647e68clevel0_row0\" class=\"row_heading level0 row0\" >Tom</th> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow0_col0\" class=\"data row0 col0\" >Male</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow0_col1\" class=\"data row0 col1\" >White</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow0_col2\" class=\"data row0 col2\" >Engineering</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow0_col3\" class=\"data row0 col3\" >23</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow0_col4\" class=\"data row0 col4\" >107962</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow0_col5\" class=\"data row0 col5\" >100</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow0_col6\" class=\"data row0 col6\" >0.2</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow0_col7\" class=\"data row0 col7\" >22</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow0_col8\" class=\"data row0 col8\" >Smith</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow0_col9\" class=\"data row0 col9\" >26592</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e5329a02_dece_11e7_9363_b8e85647e68clevel0_row1\" class=\"row_heading level0 row1\" >Niko</th> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow1_col0\" class=\"data row1 col0\" >Male</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow1_col1\" class=\"data row1 col1\" >Black</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow1_col2\" class=\"data row1 col2\" >Engineering</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow1_col3\" class=\"data row1 col3\" >1</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow1_col4\" class=\"data row1 col4\" >30347</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow1_col5\" class=\"data row1 col5\" >100</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow1_col6\" class=\"data row1 col6\" >0.1</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow1_col7\" class=\"data row1 col7\" >22</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow1_col8\" class=\"data row1 col8\" >Jones</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow1_col9\" class=\"data row1 col9\" >8034</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e5329a02_dece_11e7_9363_b8e85647e68clevel0_row2\" class=\"row_heading level0 row2\" >Penelope</th> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow2_col0\" class=\"data row2 col0\" >Female</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow2_col1\" class=\"data row2 col1\" >White</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow2_col2\" class=\"data row2 col2\" >Engineering</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow2_col3\" class=\"data row2 col3\" >12</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow2_col4\" class=\"data row2 col4\" >60258</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow2_col5\" class=\"data row2 col5\" >100</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow2_col6\" class=\"data row2 col6\" >0</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow2_col7\" class=\"data row2 col7\" >22</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow2_col8\" class=\"data row2 col8\" >Williams</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow2_col9\" class=\"data row2 col9\" >5000</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e5329a02_dece_11e7_9363_b8e85647e68clevel0_row3\" class=\"row_heading level0 row3\" >Aria</th> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow3_col0\" class=\"data row3 col0\" >Female</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow3_col1\" class=\"data row3 col1\" >Black</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow3_col2\" class=\"data row3 col2\" >Engineering</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow3_col3\" class=\"data row3 col3\" >8</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow3_col4\" class=\"data row3 col4\" >43618</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow3_col5\" class=\"data row3 col5\" >99</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow3_col6\" class=\"data row3 col6\" >0.15</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow3_col7\" class=\"data row3 col7\" >22</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow3_col8\" class=\"data row3 col8\" >Green</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow3_col9\" class=\"data row3 col9\" >11542</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e5329a02_dece_11e7_9363_b8e85647e68clevel0_row4\" class=\"row_heading level0 row4\" >Sofia</th> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow4_col0\" class=\"data row4 col0\" >Female</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow4_col1\" class=\"data row4 col1\" >Black</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow4_col2\" class=\"data row4 col2\" >Parks & Recreation</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow4_col3\" class=\"data row4 col3\" >23</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow4_col4\" class=\"data row4 col4\" >26125</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow4_col5\" class=\"data row4 col5\" >99</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow4_col6\" class=\"data row4 col6\" >0.12</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow4_col7\" class=\"data row4 col7\" >22</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow4_col8\" class=\"data row4 col8\" >Brown</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow4_col9\" class=\"data row4 col9\" >3135</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e5329a02_dece_11e7_9363_b8e85647e68clevel0_row5\" class=\"row_heading level0 row5\" >Dean</th> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow5_col0\" class=\"data row5 col0\" >Male</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow5_col1\" class=\"data row5 col1\" >Black</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow5_col2\" class=\"data row5 col2\" >Parks & Recreation</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow5_col3\" class=\"data row5 col3\" >3</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow5_col4\" class=\"data row5 col4\" >33592</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow5_col5\" class=\"data row5 col5\" >99</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow5_col6\" class=\"data row5 col6\" >0.3</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow5_col7\" class=\"data row5 col7\" >22</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow5_col8\" class=\"data row5 col8\" >Simpson</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow5_col9\" class=\"data row5 col9\" >10077</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e5329a02_dece_11e7_9363_b8e85647e68clevel0_row6\" class=\"row_heading level0 row6\" >Zach</th> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow6_col0\" class=\"data row6 col0\" >Male</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow6_col1\" class=\"data row6 col1\" >White</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow6_col2\" class=\"data row6 col2\" >Parks & Recreation</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow6_col3\" class=\"data row6 col3\" >4</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow6_col4\" class=\"data row6 col4\" >37565</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow6_col5\" class=\"data row6 col5\" >100</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow6_col6\" class=\"data row6 col6\" >0.05</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow6_col7\" class=\"data row6 col7\" >22</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow6_col8\" class=\"data row6 col8\" >Peters</td> \n",
       "        <td id=\"T_e5329a02_dece_11e7_9363_b8e85647e68crow6_col9\" class=\"data row6 col9\" >1878</td> \n",
       "    </tr></tbody> \n",
       "</table> "
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x107a4d7b8>"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_orig = df.copy()\n",
    "\n",
    "df.loc[df['DEPARTMENT'] == 'Engineering', 'BONUS'] += 5000\n",
    "style_diff(df, df_orig)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Assigning with multiple condition boolean selection\n",
    "Let's do an example with multiple boolean conditions. Let's subtract 10 from the **`SCORE`** of all the black females and white males."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>GENDER</th>\n",
       "      <th>RACE</th>\n",
       "      <th>DEPARTMENT</th>\n",
       "      <th>YEARS EXPERIENCE</th>\n",
       "      <th>SALARY</th>\n",
       "      <th>SCORE</th>\n",
       "      <th>BONUS RATE</th>\n",
       "      <th>FLOOR</th>\n",
       "      <th>LAST NAME</th>\n",
       "      <th>BONUS</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Tom</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>23</td>\n",
       "      <td>107962</td>\n",
       "      <td>100</td>\n",
       "      <td>0.20</td>\n",
       "      <td>22</td>\n",
       "      <td>Smith</td>\n",
       "      <td>26592</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aria</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>8</td>\n",
       "      <td>43618</td>\n",
       "      <td>99</td>\n",
       "      <td>0.15</td>\n",
       "      <td>22</td>\n",
       "      <td>Green</td>\n",
       "      <td>11542</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sofia</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>23</td>\n",
       "      <td>26125</td>\n",
       "      <td>99</td>\n",
       "      <td>0.12</td>\n",
       "      <td>22</td>\n",
       "      <td>Brown</td>\n",
       "      <td>3135</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zach</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>4</td>\n",
       "      <td>37565</td>\n",
       "      <td>100</td>\n",
       "      <td>0.05</td>\n",
       "      <td>22</td>\n",
       "      <td>Peters</td>\n",
       "      <td>1878</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       GENDER   RACE          DEPARTMENT  YEARS EXPERIENCE  SALARY  SCORE  \\\n",
       "Tom      Male  White         Engineering                23  107962    100   \n",
       "Aria   Female  Black         Engineering                 8   43618     99   \n",
       "Sofia  Female  Black  Parks & Recreation                23   26125     99   \n",
       "Zach     Male  White  Parks & Recreation                 4   37565    100   \n",
       "\n",
       "       BONUS RATE  FLOOR LAST NAME  BONUS  \n",
       "Tom          0.20     22     Smith  26592  \n",
       "Aria         0.15     22     Green  11542  \n",
       "Sofia        0.12     22     Brown   3135  \n",
       "Zach         0.05     22    Peters   1878  "
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# check our logic first\n",
    "white_male = (df['GENDER'] == 'Male') & (df['RACE'] == 'White')\n",
    "black_female = (df['GENDER'] == 'Female') & (df['RACE'] == 'Black')\n",
    "criteria = white_male | black_female\n",
    "df[criteria]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style  type=\"text/css\" >\n",
       "    #T_e53c5a58_dece_11e7_97f8_b8e85647e68crow0_col5 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }    #T_e53c5a58_dece_11e7_97f8_b8e85647e68crow3_col5 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }    #T_e53c5a58_dece_11e7_97f8_b8e85647e68crow4_col5 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }    #T_e53c5a58_dece_11e7_97f8_b8e85647e68crow6_col5 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }</style>  \n",
       "<table id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68c\" > \n",
       "<thead>    <tr> \n",
       "        <th class=\"blank level0\" ></th> \n",
       "        <th class=\"col_heading level0 col0\" >GENDER</th> \n",
       "        <th class=\"col_heading level0 col1\" >RACE</th> \n",
       "        <th class=\"col_heading level0 col2\" >DEPARTMENT</th> \n",
       "        <th class=\"col_heading level0 col3\" >YEARS EXPERIENCE</th> \n",
       "        <th class=\"col_heading level0 col4\" >SALARY</th> \n",
       "        <th class=\"col_heading level0 col5\" >SCORE</th> \n",
       "        <th class=\"col_heading level0 col6\" >BONUS RATE</th> \n",
       "        <th class=\"col_heading level0 col7\" >FLOOR</th> \n",
       "        <th class=\"col_heading level0 col8\" >LAST NAME</th> \n",
       "        <th class=\"col_heading level0 col9\" >BONUS</th> \n",
       "    </tr></thead> \n",
       "<tbody>    <tr> \n",
       "        <th id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68clevel0_row0\" class=\"row_heading level0 row0\" >Tom</th> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow0_col0\" class=\"data row0 col0\" >Male</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow0_col1\" class=\"data row0 col1\" >White</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow0_col2\" class=\"data row0 col2\" >Engineering</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow0_col3\" class=\"data row0 col3\" >23</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow0_col4\" class=\"data row0 col4\" >107962</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow0_col5\" class=\"data row0 col5\" >90</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow0_col6\" class=\"data row0 col6\" >0.2</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow0_col7\" class=\"data row0 col7\" >22</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow0_col8\" class=\"data row0 col8\" >Smith</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow0_col9\" class=\"data row0 col9\" >26592</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68clevel0_row1\" class=\"row_heading level0 row1\" >Niko</th> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow1_col0\" class=\"data row1 col0\" >Male</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow1_col1\" class=\"data row1 col1\" >Black</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow1_col2\" class=\"data row1 col2\" >Engineering</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow1_col3\" class=\"data row1 col3\" >1</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow1_col4\" class=\"data row1 col4\" >30347</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow1_col5\" class=\"data row1 col5\" >100</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow1_col6\" class=\"data row1 col6\" >0.1</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow1_col7\" class=\"data row1 col7\" >22</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow1_col8\" class=\"data row1 col8\" >Jones</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow1_col9\" class=\"data row1 col9\" >8034</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68clevel0_row2\" class=\"row_heading level0 row2\" >Penelope</th> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow2_col0\" class=\"data row2 col0\" >Female</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow2_col1\" class=\"data row2 col1\" >White</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow2_col2\" class=\"data row2 col2\" >Engineering</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow2_col3\" class=\"data row2 col3\" >12</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow2_col4\" class=\"data row2 col4\" >60258</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow2_col5\" class=\"data row2 col5\" >100</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow2_col6\" class=\"data row2 col6\" >0</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow2_col7\" class=\"data row2 col7\" >22</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow2_col8\" class=\"data row2 col8\" >Williams</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow2_col9\" class=\"data row2 col9\" >5000</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68clevel0_row3\" class=\"row_heading level0 row3\" >Aria</th> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow3_col0\" class=\"data row3 col0\" >Female</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow3_col1\" class=\"data row3 col1\" >Black</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow3_col2\" class=\"data row3 col2\" >Engineering</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow3_col3\" class=\"data row3 col3\" >8</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow3_col4\" class=\"data row3 col4\" >43618</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow3_col5\" class=\"data row3 col5\" >89</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow3_col6\" class=\"data row3 col6\" >0.15</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow3_col7\" class=\"data row3 col7\" >22</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow3_col8\" class=\"data row3 col8\" >Green</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow3_col9\" class=\"data row3 col9\" >11542</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68clevel0_row4\" class=\"row_heading level0 row4\" >Sofia</th> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow4_col0\" class=\"data row4 col0\" >Female</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow4_col1\" class=\"data row4 col1\" >Black</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow4_col2\" class=\"data row4 col2\" >Parks & Recreation</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow4_col3\" class=\"data row4 col3\" >23</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow4_col4\" class=\"data row4 col4\" >26125</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow4_col5\" class=\"data row4 col5\" >89</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow4_col6\" class=\"data row4 col6\" >0.12</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow4_col7\" class=\"data row4 col7\" >22</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow4_col8\" class=\"data row4 col8\" >Brown</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow4_col9\" class=\"data row4 col9\" >3135</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68clevel0_row5\" class=\"row_heading level0 row5\" >Dean</th> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow5_col0\" class=\"data row5 col0\" >Male</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow5_col1\" class=\"data row5 col1\" >Black</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow5_col2\" class=\"data row5 col2\" >Parks & Recreation</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow5_col3\" class=\"data row5 col3\" >3</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow5_col4\" class=\"data row5 col4\" >33592</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow5_col5\" class=\"data row5 col5\" >99</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow5_col6\" class=\"data row5 col6\" >0.3</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow5_col7\" class=\"data row5 col7\" >22</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow5_col8\" class=\"data row5 col8\" >Simpson</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow5_col9\" class=\"data row5 col9\" >10077</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68clevel0_row6\" class=\"row_heading level0 row6\" >Zach</th> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow6_col0\" class=\"data row6 col0\" >Male</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow6_col1\" class=\"data row6 col1\" >White</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow6_col2\" class=\"data row6 col2\" >Parks & Recreation</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow6_col3\" class=\"data row6 col3\" >4</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow6_col4\" class=\"data row6 col4\" >37565</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow6_col5\" class=\"data row6 col5\" >90</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow6_col6\" class=\"data row6 col6\" >0.05</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow6_col7\" class=\"data row6 col7\" >22</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow6_col8\" class=\"data row6 col8\" >Peters</td> \n",
       "        <td id=\"T_e53c5a58_dece_11e7_97f8_b8e85647e68crow6_col9\" class=\"data row6 col9\" >1878</td> \n",
       "    </tr></tbody> \n",
       "</table> "
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x107ae6710>"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_orig = df.copy()\n",
    "df.loc[criteria, 'SCORE'] -= 10\n",
    "style_diff(df, df_orig)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Assigning subsets of data in a Series\n",
    "Assigning subsets of pandas Series is a less common operation but happens analogously to a DataFrame.\n",
    "\n",
    "Let's first select a copy of the **`SALARY`** column from our above DataFrame:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Tom         107962\n",
       "Niko         30347\n",
       "Penelope     60258\n",
       "Aria         43618\n",
       "Sofia        26125\n",
       "Dean         33592\n",
       "Zach         37565\n",
       "Name: SALARY, dtype: int64"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = df['SALARY'].copy()\n",
    "s"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We didn't have to use the **`copy`** method, but we did so to avoid the **`SettingWithCopy`** warning. This is a common warning when making assignments during subset selection. We will cover what it means and how to avoid it in the next notebook."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Assigning with `.loc` and `.iloc`\n",
    "Since Series do not have columns, I don't use *just the indexing operator* with them (unless I am doing boolean selection). It can be used to select rows, but is ambiguous and confusing and therefore I avoid it. All the capability of explicitly selecting particular Series values is provided with **`.loc`** and **`.iloc`**.\n",
    "\n",
    "Let's change the salary of **`Tom`**, **`Sofia`**, and **`Zach`**."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Tom         99999\n",
       "Niko        30347\n",
       "Penelope    60258\n",
       "Aria        43618\n",
       "Sofia       39999\n",
       "Dean        33592\n",
       "Zach        49999\n",
       "Name: SALARY, dtype: int64"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.loc[['Tom', 'Sofia', 'Zach']] = [99999, 39999, 49999]\n",
    "s"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## No styling with Series\n",
    "Pandas outputs Series as plain text, so we cannot style them like we do with DataFrames.\n",
    "\n",
    "However, we can create a function to modify the index by appending '-changed' to the ones that have changed."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# advanced\n",
    "def style_diff_series(s, s_orig):\n",
    "    idx = s.index.where(s == s_orig, s.index + '-changed')\n",
    "    return s.set_axis(idx, inplace=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Create a copy of our original like we did before:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "s = df['SALARY'].copy()\n",
    "s_orig = s.copy()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Apply the changes:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "s.loc[['Tom', 'Sofia', 'Zach']] = [99999, 39999, 49999]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Add 'changed' to the index:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Tom-changed      99999\n",
       "Niko             30347\n",
       "Penelope         60258\n",
       "Aria             43618\n",
       "Sofia-changed    39999\n",
       "Dean             33592\n",
       "Zach-changed     49999\n",
       "Name: SALARY, dtype: int64"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "style_diff_series(s, s_orig)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can make similar changes using integer location with **`.iloc`**. Here we change every other value."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Tom-changed         55555\n",
       "Niko                30347\n",
       "Penelope-changed    55555\n",
       "Aria                43618\n",
       "Sofia-changed       55555\n",
       "Dean                33592\n",
       "Zach-changed        55555\n",
       "Name: SALARY, dtype: int64"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s_orig = s.copy()\n",
    "s.iloc[::2]  = 55555\n",
    "style_diff_series(s, s_orig)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Assigning Series with boolean indexing\n",
    "We can use boolean indexing to make assignments as well. Using *just the indexing operator* is acceptable here. Let's double all the salaries below 40,000"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Tom             55555\n",
       "Niko-changed    60694\n",
       "Penelope        55555\n",
       "Aria            43618\n",
       "Sofia           55555\n",
       "Dean-changed    67184\n",
       "Zach            55555\n",
       "Name: SALARY, dtype: int64"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s_orig = s.copy()\n",
    "s[s < 40000] *= 2\n",
    "style_diff_series(s, s_orig)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Both *just the indexing operator* and **`.loc`** work the same when doing boolean indexing on a Series. However, as mentioned in part 2, **`.iloc`** should almost never be used when doing boolean indexing as it's not implemented fully."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Summary\n",
    "\n",
    "* Assignment means using the equal sign to assign a variable on the left-hand side to an expression on the right-hand side\n",
    "* New columns are created by passing a string to *just the indexing operator* and setting it equal to either a scalar, a list/array the same length as the DataFrame, or a Series with identical index as the DataFrame\n",
    "* There is no output when you make an assignment. You must use an extra line to display the DataFrame/Series\n",
    "* Select a specific subset of rows/columns with **`.loc`** or **`.iloc`** and manually assign them value with a list/array.\n",
    "* Use the **`style`** attribute to make particular values pop out for visual display\n",
    "* You can assign entire columns with **`.loc`** or **`.iloc`** by using the colon, **`:`** for rows\n",
    "* A more common operation is to use boolean indexing to select subsets of data before making an assignment\n",
    "* Assigning new values to a Series is similar to DataFrames except that we don't use **`.iloc`** for boolean indexing"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Just the basics of assignment of subsets\n",
    "This tutorial covered the simplest and most frequently used assignment of subsets. The next notebook will cover some things NOT to do like **chained indexing** and triggering the **`SettingWithCopy`** warning.\n",
    "\n",
    "There are also many other ways to create new columns or even add multiple columns at the same time. This notebook again, is just drilling the basics.\n",
    "\n",
    "# Exercises\n",
    "We will continue to use the employee sample DataFrame for all the exercises in this tutorial"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>GENDER</th>\n",
       "      <th>RACE</th>\n",
       "      <th>DEPARTMENT</th>\n",
       "      <th>YEARS EXPERIENCE</th>\n",
       "      <th>SALARY</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Tom</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>23</td>\n",
       "      <td>107962</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Niko</th>\n",
       "      <td>Male</td>\n",
       "      <td>Black</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>1</td>\n",
       "      <td>30347</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Penelope</th>\n",
       "      <td>Female</td>\n",
       "      <td>White</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>12</td>\n",
       "      <td>60258</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aria</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>8</td>\n",
       "      <td>43618</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sofia</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>23</td>\n",
       "      <td>26125</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dean</th>\n",
       "      <td>Male</td>\n",
       "      <td>Black</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>3</td>\n",
       "      <td>33592</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zach</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>4</td>\n",
       "      <td>37565</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          GENDER   RACE          DEPARTMENT  YEARS EXPERIENCE  SALARY\n",
       "Tom         Male  White         Engineering                23  107962\n",
       "Niko        Male  Black         Engineering                 1   30347\n",
       "Penelope  Female  White         Engineering                12   60258\n",
       "Aria      Female  Black         Engineering                 8   43618\n",
       "Sofia     Female  Black  Parks & Recreation                23   26125\n",
       "Dean        Male  Black  Parks & Recreation                 3   33592\n",
       "Zach        Male  White  Parks & Recreation                 4   37565"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv('../../data/employee_sample.csv', index_col=0)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def style_diff(df, df_orig):\n",
    "    style = {True: '', \n",
    "             False: 'color: red; background-color: yellow'}\n",
    "    df_style = (df == df_orig).replace(style)\n",
    "    return df.style.apply(lambda x: df_style, axis=None)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 1\n",
    "<span  style=\"color:green; font-size:16px\"> Create a Series with the index equal to the same values in **`df`** but in a different order. Make the values of the Series integers representing the employee's age ranging somewhere from 20 to 65. Create a new column **`AGE`**. Does the order of the index matter?</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# your code here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 2\n",
    "<span  style=\"color:green; font-size:16px\"> Create a new column **`BONUS`** equal to 0 for everyone</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# your code here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 3\n",
    "<span  style=\"color:green; font-size:16px\"> Change the **`BONUS`** column so that everyone with more than 10 years of experience get $10,000. Use the **`style_diff`** function to display the results.</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# your code here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 4\n",
    "<span  style=\"color:green; font-size:16px\"> Create a new column **`TOTAL SALARY`** that is 10% higher than the current **`SALARY`** column and add the bonus on top of that as well. Use **`.loc`** on the left-hand side and NOT *just the indexing operator*. Make the data type **`TOTAL SALARY`** an integer.</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# your code here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 5\n",
    "<span  style=\"color:green; font-size:16px\"> Set Aria's department to 'Police'. Highlight the change</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# your code here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 6\n",
    "<span  style=\"color:green; font-size:16px\"> Give all the white engineers a salary raise of \\$10,000 and all the black Parks & Recreation employees a decrease in salary by \\$10,000. Highlight the change.</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# your code here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 7\n",
    "<span  style=\"color:green; font-size:16px\"> Use **`.iloc`** to change the age of the employees with integer location 3 and 5 to 60 and 65 respectively. Highlight the change.</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# your code here"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
